import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'//用于包含侧边栏、顶部导航栏等公共部分。

/**
 * ⭐路由配置说明
 * Note: sub-menu only appear when route children.length >= 1
 * 子菜单仅当路由的   children   数组长度大于等于 1 时出现。即一个路由如果有子路由，才会在侧边栏显示为子菜单形式。
 *
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * ⭐路由配置项解释
 * hidden: true                   如果设置为   true  ，该项不会在侧边栏显示，默认为   false  。
 * alwaysShow: true               如果设置为   true  ，会始终显示根菜单。
 *                                如果不设置   alwaysShow  ，当该项有多个子路由时，
 *                                会变为嵌套模式(nested mode)；否则不显示根菜单。
 * redirect: noRedirect           如果设置为   noRedirect  ，在面包屑(breadcrumb)导航中不会进行重定向。
 * name:'router-name'             路由名称，用于   <keep-alive>   组件中（必须设置!!!）
 * meta : {
    roles: ['admin','editor']    控制页面角色，可以设置多个角色
    title: 'title'               在侧边栏和面包屑导航中显示的名称（建议设置）。
    icon: 'svg-name'/'el-icon-x' 在侧边栏显示的图标，可以是 SVG 名称或 Element UI 图标
    breadcrumb: false            如果设置为   false  ，该项在面包屑导航中不会显示，默认为   true
    activeMenu: '/example/list'  如果设置路径，侧边栏会高亮显示你设置的路径。
  }
 */

/**
 * constantRoutes 常量路由，不会受权限控制，如登录页、404、500等页面。
 * a base page that does not have permission requirements
 * all roles can be accessed
 *
 * asyncRoutes 动态路由，需要根据权限动态判断加载。
 * the routes that need to be dynamically loaded based on user roles
 * only admin role can access
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },



  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'dashboard', affix: true },
    }]
  },

  {
    path: '/org',
    component: Layout,
    redirect: '/org/index',
    children: [{
      path: 'index',
      name: 'orgnazation',
      component: () => import('@/views/org/index'),
      meta: { title: '组织架构', icon: 'el-icon-s-grid' }
    }]
  },

  {
    path: '/article',
    component: Layout,
    children: [{
      path: 'article',
      name: 'article',
      component: () => import('@/views/article/index'),
      meta: { title: '公告', icon: 'form' }
    }]
  },

  {
    path: '/stat',
    component: Layout,
    redirect: '/stat/index',
    children: [{
      path: 'index',
      name: 'durationStatistics',
      component: () => import('@/views/stat/index'),
      meta: { title: '时长统计', icon: 'el-icon-s-data' }
    }]
  },

  {
    path: '/task',
    component: Layout,
    redirect: '/task/index',
    meta: { title: '任务中心', icon: 'el-icon-folder-add' },
    children: [
      {
        path: 'index',
        name: 'taskIndex',
        component: () => import('@/views/task/index'),
        meta: { title: '任务列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'taskAdd',
        hidden: true,
        component: () => import('@/views/task/add'),
        meta: { title: '任务添加&编辑', icon: 'el-icon-folder-add' }
      },
    ],
  },

  {
    path: '/member',
    component: Layout,
    redirect: '/member/index',
    children: [{
      path: 'index',
      name: 'member',
      component: () => import('@/views/member/index'),
      meta: { title: '队员管理', icon: 'el-icon-user-solid' }
    }]
  },



  {
    path: '/example',
    component: Layout,
    redirect: '/example/tree',
    name: 'Example',
    meta: { title: 'Example', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: 'Tree', icon: 'tree' }
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
